﻿{% extends "base.html" %}
{% block title %} 分配任务 {% endblock %}
{% block user %} 分配任务 {% endblock %}
{% block styles %}{{super()}}
<link href="{{ url_for("static", filename="css/dashboard.css") }}" rel="stylesheet">
<style>
  .col-center-block {
    float: none;
    display: block;
    margin-left: auto;
    margin-right: auto;
  }
</style>
{% endblock %}
{% block scripts %}{{super()}}
<script>
  $(function () {
    $('.datepicker').datepicker({
      format: 'mm/dd/yyyy',
      startDate: '-1m',
      todayBtn: true,
      todayHighlight: true
    });
    {% if assignment %}
    $('#jobnumber option[value="{{ assignment[8] }}"]').prop("selected", true);
    $('.selectpicker').selectpicker('refresh');
    {% endif %}
  });
</script>
{% endblock %}


{% block content %}
<div class="container-fluid">
  <div class="main">
    <div class="row">
      <div class="col-xs-12 col-sm-12 col-md-11 col-lg-8 col-center-block">
        {% include 'flash_message.html' %}
        <h3 class="row page-header" style="text-align:center">
          {% if view %}
          {{ users[1][1] }} 的任务
          {% else %}
          {{ users[0][1] }} 向 {{ users[1][1] }} 分配任务
          {% endif %}
        </h3>

        {% if assignment %}
        <form class="form-horizontal" action="{{ url_for('bp_partner.assign', user_id=users[1][0]) }}" method="POST">

          <div class="form-group">
            <label for="jobno" class="col-sm-2 control-label">工作令号</label>
            <div class="col-sm-10">
              <select id="jobnumber" class="selectpicker form-control" name="jobnumberid" title="选择工作令号"
                data-show-subtext="true" data-live-search="true" required>
                {% for jobnumber in jobnumbers %}
                <option value="{{ jobnumber[0] }}">{{ jobnumber[1] + '\t' +jobnumber[2]  }}</option>
                {% endfor %}
              </select>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">任务摘要</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" name="title" value="{{ assignment[1] }}" required>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">任务明细</label>
            <div class="col-sm-10">
              <textarea class="form-control" rows="3" name="remark">{{ assignment[2] }}</textarea>
            </div>
          </div>


          <input style="display: none" type="text" class="form-control" name="senderid" value="{{ users[0][0] }}"
            required>
          <input style="display: none" type="text" class="form-control" name="receiverid" value="{{ users[1][0] }}"
            required>
          <input style="display: none" type="text" class="form-control" name="assignmentid" value="{{ assignment[0] }}"
            required>


          <div class="form-group">
            <label class="col-sm-2 control-label">开始日期</label>
            <div class="col-sm-10">
              <input type="text" class="datepicker form-control" name="startdate"
                value="{{ assignment[3].strftime('%m/%d/%Y')  }}" required>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">结束日期</label>
            <div class="col-sm-10">
              <input type="text" class="datepicker form-control" name="enddate"
                value="{{ assignment[4].strftime('%m/%d/%Y')  }}" required>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">权重</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" name="taskrate" placeholder="0~1" pattern="^0\.[0-9]{0,5}$|1"
                value="{{ assignment[5] }}" required>
            </div>
          </div>


          <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
              {% if not view %}
              <button type="submit" class="btn btn-danger">修改</button>
              {% endif %}
              {#      <button class="btn btn-default" onclick="javascript:history.go(-1)">返回</button>#}
            </div>
          </div>

        </form>

        {% if attachments %}
        <table class="table table-striped table-hover table-bordered">
          <tr>
            <th>id</th>
            <th>文件名</th>
            <th>上传时间</th>
            <th>删除时间</th>
            <th>状态</th>
          </tr>

          {% for attachment in attachments %}
          {%  if attachment.delete %}
          <tr class="danger">
            {% else %}
          <tr class="success">
            {% endif %}
            <td>{{ attachment.id }}</td>
            <td><a
                href="{{ url_for('bp_partner.download', file_name=attachment.file_name, attachment_id=attachment.id) }}">{{ attachment.display_name }}</a>
            </td>
            <td>{{ attachment.create_time }}</td>
            <td>{{ attachment.edit_time }}</td>
            <td>
              {%  if not attachment.delete %}
              有效
              {% else %}
              作废
              {% endif %}
            </td>
          </tr>
          {% endfor %}
        </table>
        {% endif %}

        {% else %}
        <form class="form-horizontal" action="{{ url_for('bp_partner.assign', user_id=users[1][0]) }}" method="POST">

          <div class="form-group">
            <label for="jobno" class="col-sm-2 control-label">工作令号</label>
            <div class="col-sm-10">
              <select class="selectpicker form-control" name="jobnumberid" title="选择工作令号" data-show-subtext="true"
                data-live-search="true" required>
                {% for jobnumber in jobnumbers %}
                <option value="{{ jobnumber[0] }}">{{ jobnumber[1] + '\t' +jobnumber[2]  }}</option>
                {% endfor %}
              </select>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">任务摘要</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" name="title" required>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">任务明细</label>
            <div class="col-sm-10">
              <textarea class="form-control" rows="3" name="remark"></textarea>
            </div>
          </div>


          <input style="display: none" type="text" class="form-control" name="senderid" value="{{ users[0][0] }}"
            required>
          <input style="display: none" type="text" class="form-control" name="receiverid" value="{{ users[1][0] }}"
            required>


          <div class="form-group">
            <label class="col-sm-2 control-label">开始日期</label>
            <div class="col-sm-10">
              <input type="text" class="datepicker form-control" name="startdate" required>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">结束日期</label>
            <div class="col-sm-10">
              <input type="text" class="datepicker form-control" name="enddate" required>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">权重</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" name="taskrate" placeholder="0~1" pattern="^0\.[0-9]{0,5}$|1"
                required>
            </div>
          </div>


          <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
              <button type="submit" class="btn btn-success">提交</button>
              <button class="btn btn-default" onclick="javascript:history.go(-1)">返回</button>
            </div>
          </div>
        </form>
        {% endif %}
      </div>
    </div>
  </div>
</div>
{% endblock %}